package com.alks.function.controller.biocontrol.deptwork;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.entity.data.entity.PcKpiDeptPersons;
import com.alks.entity.data.entity.PcProdTotalWeekTarget;
import com.alks.entity.data.page.PageParam;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.biocontrol.deptwork.KpiPersonRequest;
import com.alks.function.data.request.biocontrol.deptwork.ProdMonthRequest;
import com.alks.function.service.biocontrol.deptwork.IProdTagService;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@ApiRestController("/bioDeptWrok")
@Api(value = "生控作业", tags = "生控部-生控作业-生产目标分析")
@RequiredArgsConstructor
@RoleCheck(prgIds = "140113")
public class ProdTagController {
    private final IProdTagService service;

    @PutMapping("/getProdMonthQuery")
    @ApiOperation(value = "月生产状况查询-查询", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo getProdMonthQuery(@RequestBody PageParam request,
                                          @RequestParam @ApiParam("日期")@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate month,
                                          @RequestParam @ApiParam("是否显示明细 N则不显示") String deptFlag) {
        return service.getProdMonthQuery(request, month.atStartOfDay(), deptFlag);
    }

    @PutMapping("/prodMonthAdd")
    @ApiOperation(value = "月生产状况新增-新增", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo prodMonthAdd(@RequestBody ProdMonthRequest request) {
        return service.prodMonthAdd(request);
    }

    @PutMapping("/prodMonthUp")
    @ApiOperation(value = "月生产状况修改-更新", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo prodMonthUp(@RequestBody ProdMonthRequest request,
                                    @RequestParam @ApiParam("月份") String monthOld,
                                    @RequestParam @ApiParam("序号") String seqNoOld) {
        return service.prodMonthUp(request,monthOld,seqNoOld);
    }

    @PostMapping("/prodMonthDelete")
    @ApiOperation(value = "月生产状况删除-删除", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo prodMonthDelete(@RequestParam @ApiParam("日期") String month,
                                        @RequestParam @ApiParam("序号") String seqNo) {
        return service.prodMonthDelete(month, seqNo);
    }

    @GetMapping("/getProdWeekQuery")
    @ApiOperation(value = "周生产状况查询-查询", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo getProdWeekQuery() {
        return service.getProdWeekQuery();
    }

    @GetMapping("/getProTarDefQuery")
    @ApiOperation(value = "周目标自定义查询-查询", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo getProTarDefQuery() {
        return service.getProTarDefQuery();
    }

    @PostMapping("/proTarDefAdd")
    @ApiOperation(value = "周目标自定义新增-新增", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo proTarDefAdd(@RequestParam @ApiParam("部门名称") String deptName,
                                     @RequestParam @ApiParam("目标数量") BigDecimal weekTargetQty) {
        return service.proTarDefAdd(deptName, weekTargetQty);
    }

    @PostMapping("/proTarDefUpdate")
    @ApiOperation(value = "周目标自定义更新-更新", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo proTarDefUpdate(@RequestBody PcProdTotalWeekTarget request,
                                        @RequestParam @ApiParam("部门名称") String deptNameOld,
                                        @RequestParam @ApiParam("目标数量") String weekTargetQtyOld) {
        return service.proTarDefUpdate(request, deptNameOld, weekTargetQtyOld);
    }

    @PostMapping("/proTarDefDelete")
    @ApiOperation(value = "周目标自定义删除-删除", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo proTarDefDelete(@RequestParam @ApiParam("部门名称") String deptName,
                                        @RequestParam @ApiParam("目标数量") String weekTargetQty) {
        return service.proTarDefDelete(deptName, weekTargetQty);
    }

    @GetMapping("/getProdPersonQuery")
    @ApiOperation(value = "人均效能状况查询-查询", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo getProdPersonQuery() {
        return service.getProdPersonQuery();
    }

    @PutMapping("/getkpiPersonQuery")
    @ApiOperation(value = "产量人数定义查询-查询", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo getKpiPersonQuery(@RequestBody KpiPersonRequest request) {
        return service.getkpiPersonQuery(request);
    }

    @PutMapping("/kpiPersonAdd")
    @ApiOperation(value = "产量人数定义新增-新增", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo kpiPersonAdd(@RequestBody PcKpiDeptPersons request) {
        return service.kpiPersonAdd(request);
    }

    @PutMapping("/kpiPersonUp")
    @ApiOperation(value = "产量人数定义修改-更新", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo kpiPersonUp(@RequestBody PcKpiDeptPersons request,
                                    @RequestParam@ApiParam("部门类别") String deptTypeOld,
                                    @RequestParam@ApiParam("部门名称") String deptNameOld,
                                    @RequestParam@ApiParam("日期")
                                    @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dDateOld) {
        return service.kpiPersonUp(request, deptTypeOld, deptNameOld, dDateOld);
    }

    @PostMapping("/kpiPersonDelete")
    @ApiOperation(value = "产量人数定义删除-删除", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo kpiPersonDelete(@RequestParam@ApiParam("部门类别") String deptType,
                                        @RequestParam@ApiParam("部门名称") String deptName,
                                        @RequestParam@ApiParam("日期")
                                        @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dDate) {
        return service.kpiPersonDelete(deptType,deptName,dDate);
    }
    
    @PutMapping("/getMonthHolidayQuery")
    @ApiOperation(value = "放假日期查询-查询", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo getMonthHolidayQuery(@RequestBody PageParam request,
                                             @RequestParam@ApiParam("日期")
                                             @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dDate) {
        return service.getMonthHolidayQuery(request,dDate);
    }

    @PostMapping("/MonthHolidayAdd")
    @ApiOperation(value = "放假日期新增-新增", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo MonthHolidayAdd(@RequestParam@ApiParam("日期") @DateTimeFormat(pattern = "yyyy-MM-dd")
                                        LocalDate dDate) {
        return service.MonthHolidayAdd(dDate);
    }

    @PostMapping("/MonthHolidayUp")
    @ApiOperation(value = "放假日期修改-更新", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo MonthHolidayUp(@RequestParam@ApiParam("日期")
                                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dDate,
                                       @RequestParam@ApiParam("旧日期")
                                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dDateOld) {
        return service.MonthHolidayUp(dDate,dDateOld);
    }

    @PostMapping("/MonthHolidayDelete")
    @ApiOperation(value = "放假日期删除-删除", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo MonthHolidayDelete(@RequestParam@ApiParam("日期") @DateTimeFormat(pattern = "yyyy-MM-dd")
                                               LocalDate dDate) {
        return service.MonthHolidayDelete(dDate);
    }

    @GetMapping("/MonthDeptType")
    @ApiOperation(value = "部门类别-回显", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo MonthDeptType() {
        return service.MonthDeptType();
    }

    @PostMapping("/prodUpdate")
    @ApiOperation(value = "取资料-查询", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo prodUpdate(@RequestParam@JsonDeserialize(using = LocalDateDeserializer.class)
                                       @ApiParam(value = "日期",required = true) LocalDateTime month) {
        return service.prodUpdate(month);
    }

    @PostMapping("/lastMonthUp")
    @ApiOperation(value = "取指定月设定资料-更新", tags = "生控部-生控作业-生产目标分析")
    public ResponseInfo lastMonthUp(@RequestParam@JsonDeserialize(using = LocalDateDeserializer.class)
                                    @ApiParam(value = "日期",required = true) LocalDateTime month,
                                    @RequestParam(required = false)@JsonDeserialize(using = LocalDateDeserializer.class)
                                    @ApiParam("目标日期") LocalDateTime tagMonth) {
        service.lastMonthUp(month,tagMonth);
        return ResponseInfo.ok();
    }


}

